
// Source File Name:   BAG_ENImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BAG_EN;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.EN;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.List;


//            BAGCommonImpl, ANYImpl, CSImpl, NullFlavorImpl,
//            TYPEImpl

public class BAG_ENImpl extends BAGCommonImpl
    implements BAG_EN
{

    public static final String RCS_ID = "$Header: BAG_ENImpl.java 1.0 2006/09/16 09:23:35 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: BAG_ENImpl.java 1.0 2006/09/16 09:23:35 amchanda noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    private static final BAG_EN nullNI = new BAG_ENImpl(CSImpl.valueOf("NI"));
    private static final BAG_EN nullOTH = new BAG_ENImpl(CSImpl.valueOf("OTH"));
    private static final BAG_EN nullNINF = new BAG_ENImpl(CSImpl.valueOf("NINF"));
    private static final BAG_EN nullPINF = new BAG_ENImpl(CSImpl.valueOf("PINF"));
    private static final BAG_EN nullUNK = new BAG_ENImpl(CSImpl.valueOf("UNK"));
    private static final BAG_EN nullASKU = new BAG_ENImpl(CSImpl.valueOf("ASKU"));
    private static final BAG_EN nullNAV = new BAG_ENImpl(CSImpl.valueOf("NAV"));
    private static final BAG_EN nullMSK = new BAG_ENImpl(CSImpl.valueOf("MSK"));
    private static final BAG_EN nullNA = new BAG_ENImpl(CSImpl.valueOf("NA"));
    private static final BAG_EN nullNASK = new BAG_ENImpl(CSImpl.valueOf("NASK"));

    public static BAG_EN valueOf(EN aen[])
    {
        return new BAG_ENImpl(aen);
    }

    public static BAG_EN valueOf(EN en)
    {
        return new BAG_ENImpl(en);
    }

    public static BAG_EN valueOf(List list)
    {
        if(list == null)
            throw ANYImpl.newNullException("BAG<EN>", "valueOf", "list");
        else
            return new BAG_ENImpl(list);
    }

    protected BAG_ENImpl(EN aen[])
    {
        if(aen == null)
            throw ANYImpl.newNullException("BAG<EN>", "constructor", "elements");
        for(int i = 0; i < aen.length; i++)
            if(aen[i] != null && aen[i].isNull().isFalse())
                mList.add(aen[i]);

    }

    protected BAG_ENImpl(EN en)
    {
        if(en == null || en.isNull().isTrue())
        {
            throw ANYImpl.newNullException("BAG<EN>", "constructor", "element");
        } else
        {
            mList.add(en);
            return;
        }
    }

    protected BAG_ENImpl(List list)
    {
        super(list);
    }

    protected BAG_ENImpl(CS cs)
    {
        super(cs);
    }

    public INT contains(EN en)
    {
        return containsANY(en);
    }

    public BAG_EN plus(BAG_EN bag_en)
    {
        if(isNull().isTrue())
            return nullBAG_EN(NullFlavorImpl.NI);
        else
            return new BAG_ENImpl(plus(mList, bag_en.toList()));
    }

    public BAG_EN minus(BAG_EN bag_en)
    {
        if(isNull().isTrue())
            return nullBAG_EN(NullFlavorImpl.NI);
        else
            return new BAG_ENImpl(minus(mList, bag_en.toList()));
    }

    public BAG_EN promotion(EN en)
    {
        return new BAG_ENImpl(promoteItem(en));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.BAG_EN;
    }

    public BL equal(ANY any)
    {
        throw ANYImpl.newUnsupportedException("BAG<EN>", "equal");
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
            i += mList.hashCode();
        return i;
    }

    protected boolean verifyItem(Object obj)
    {
        return obj instanceof EN;
    }

    public static BAG_EN nullBAG_EN(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
